home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / PickOne / sources / PickOne_window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  3.8 KB  |  167 lines  |  [TEXT/CWIE]

  1. /*  window.c                                                                            
  2.  
  3.     Michael Bishop - August 21 1996                                                    
  4.     Nick Thompson
  5.     (c)1994-96 Apple computer Inc., All Rights Reserved                                
  6.  
  7. */
  8.  
  9. #include    <Devices.h>
  10.  
  11. #include    "PickOne_window.h"
  12. #include    "PickOne_document.h"
  13.  
  14. /* -------------------------------------------------------------------------------------------
  15. ** Window_New
  16. ** Kind of a dummy function at the moment.
  17. */
  18. WindowPtr Window_New(void)
  19. {
  20.     WindowPtr    tempWindow = GetNewCWindow( kWindowResID, NULL, (WindowPtr)-1L );
  21.     
  22.     return tempWindow ;
  23. }
  24.  
  25.  
  26. /* -------------------------------------------------------------------------------------------
  27. ** Window_Dispose
  28. ** Call this function when we are done with a window, deallocate any storage allocated for this,
  29. ** this gets called when we close a document.
  30. */
  31.  
  32. void Window_Dispose(WindowPtr theWindow)
  33. {
  34.  
  35.     if( theWindow != NULL )
  36.     {
  37.         DisposeWindow ( theWindow ) ;
  38.     }
  39.     
  40. }
  41.  
  42. /* -------------------------------------------------------------------------------------------
  43. ** Window_Update
  44. ** 
  45. */
  46. void Window_Update( WindowPtr theWindow )
  47. {
  48.  
  49.     CGrafPtr            savedPort ;
  50.     
  51.     if( theWindow != NULL ) 
  52.     {
  53.         DocumentHdl        myDocumentHandle = Window_GetDocument(theWindow);
  54.         Rect            updateRect = (**(theWindow->visRgn)).rgnBBox;
  55.         
  56.         if( myDocumentHandle != NULL )
  57.         {
  58.             GetPort((GrafPtr *) &savedPort );
  59.             SetPort( theWindow ) ;
  60.             
  61.             BeginUpdate( theWindow );
  62.             
  63.             HLock( (Handle)myDocumentHandle  ) ;
  64.             Document_Draw(*myDocumentHandle ) ;
  65.             HUnlock( (Handle)myDocumentHandle  ) ;
  66.             
  67.             EndUpdate( theWindow );
  68.             SetPort( (GrafPtr )savedPort ) ;
  69.         }
  70.     }
  71. }
  72.  
  73.  
  74. /* ---------------------------------------------------------------------------------- 
  75. **     Window_Activate
  76. **    is called when an theEvent is received that reports that
  77. **     a theWindow is being either activated or deactivated. 
  78. */
  79. void Window_Activate(WindowPtr theWindow, short activate)
  80. {
  81.     if (theWindow) {
  82.         if (activate) {
  83.         
  84.             /*  do whatever else you'd like to do for a activate theEvent */
  85.             /* LoadScrap() ;
  86.             */
  87.         } else {
  88.         
  89.             /*  do whatever you'd like to do for a deactivate theEvent */
  90.             /*UnloadScrap() ;
  91.             */
  92.         }
  93.     }
  94. }
  95.  
  96. /* -------------------------------------------------------------------------------------------
  97. ** Window_GetDocument
  98. ** Gets the document associated with a window
  99. */
  100.  
  101. DocumentHdl Window_GetDocument( WindowPtr theWindow)
  102. {
  103.     if (theWindow != NULL)
  104.         return    (DocumentHdl) GetWRefCon ( theWindow );
  105.     else return NULL;
  106. }
  107.  
  108. /* -------------------------------------------------------------------------------------------
  109. ** Window_SetDocument
  110. ** Gets the document associated with a window
  111. */
  112.  
  113. int Window_SetDocument( WindowPtr theWindow,  DocumentHdl theDocument)
  114. {
  115.     if (theWindow != NULL)
  116.     {
  117.         SetWRefCon (theWindow, (long)theDocument ) ;
  118.         return    true;
  119.     }
  120.     else return false;
  121. }
  122.  
  123.  
  124.  
  125. void Window_DoContent (WindowPtr theWindow, EventRecord *theEvent)
  126. {
  127. #pragma unused     (theEvent)
  128.  
  129.     CGrafPtr    oldPort;
  130.     DocumentHdl    theDocument = Window_GetDocument(theWindow);
  131.  
  132.     GetPort((GrafPtr *)&oldPort);
  133.     SetPort(theWindow);
  134.     
  135.     Document_DoPickAndRotate(theDocument);
  136.     
  137.     SetPort((GrafPtr)oldPort);
  138. }
  139.  
  140.  
  141. /* ---------------------------------------------------------------------------------- 
  142. **     Window_GetNextWindow
  143. **    Returns the next in the queue
  144. */
  145. WindowPtr Window_GetNextWindow(WindowPtr theWindow)
  146. {
  147.     if (theWindow != NULL)
  148.         return (WindowPtr)((WindowPeek)theWindow)->nextWindow;
  149.     else return NULL;
  150. }
  151.  
  152. /* ---------------------------------------------------------------------------------- 
  153. **     Window_DestroyAll destroys all the windows in the app
  154. **     
  155. */
  156. void Window_DestroyAll(void)
  157. {
  158.     WindowPtr theWindow;
  159.     
  160.     theWindow = FrontWindow();                        /*    Start with the active window    */
  161.     
  162.     while (theWindow != NULL)
  163.     {
  164.         Document_Dispose( Window_GetDocument(theWindow) ) ;    /*    delete it    */
  165.         theWindow = Window_GetNextWindow(theWindow);            /*    go down the list    */
  166.     }
  167. }